﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using ECare.Client.templates;

using ECare.BUS.Data;
using ECare.BUS;


namespace ECare.Client.frms
{
    public partial class frmStackerInfo : frmInfo
    {
        public frmStackerInfo()
        {
            InitializeComponent();

            this.Load += frmStackerInfo_Load;
        }

        void frmStackerInfo_Load(object sender, EventArgs e)
        {
            //throw new NotImplementedException();

            if (this.entity != null)
            {
                this.txtCode.Text = (this.entity as StackerInfo).StackerInfo_Code;
                this.txtName.Text = (this.entity as StackerInfo).StackerInfo_Name;
            }
            
        }
        public event EntitySavedHandler Saved;

        private void btnSave_Click(object sender, EventArgs e)
        {
            if (ValidateTextControl(this.txtCode) == false)
                return;

            if (ValidateTextControl(this.txtName) == false)
                return;

            if (this.entity == null)
            {
                var newstacker = new StackerInfo();
                newstacker.StackerInfo_Code = this.txtCode.Text;
                newstacker.StackerInfo_Name = this.txtName.Text;

                newstacker.StackerInfo_Id=StackerInfoHelper.CreateStackInfo(newstacker);
                this.entity = newstacker;
            }
            else
            {
                var newstacker = this.entity as StackerInfo;
                newstacker.StackerInfo_Code = this.txtCode.Text;
                newstacker.StackerInfo_Name = this.txtName.Text;

                StackerInfoHelper.UpdateStacker(newstacker); 
            }

            if (this.Saved != null)
            {
                this.Saved(this.entity);
                this.Close();
            }

        }
    }
}
